package com.sunrise.xdoc.dao.impl;

import org.hibernate.criterion.Restrictions;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Repository;

import com.sunrise.xdoc.dao.IUserDao;
import com.sunrise.xdoc.entity.user.User;

@Repository("userDao")
public class UserDao extends BaseDao<User> implements IUserDao {

	@Override
	public User loadUserByUsername(String userName) throws UsernameNotFoundException {
		User u = findFirstByCriteria(getDetachedCriteria().add(Restrictions.eq("username", userName)));
		if (u == null) {
			throw new UsernameNotFoundException("User " + userName + " is not found");
		}
		return u;
	}

}
